package main

import (
	beego "github.com/beego/beego/v2/server/web"
	"github.com/beego/beego/v2/server/web/context"
	"log"
	_ "ocane/routers"
	"strings"
)

func main() {
	beego.BConfig.Listen.EnableAdmin = true
	beego.InsertFilter("/*",beego.BeforeRouter,FilterLog)
	beego.Run()
}

var FilterLog =  func(ctx *context.Context)  {
	//params := ctx.Input.Params()
	method := ctx.Request.Method
	//ctx.Output.JSON(models.Result{Data: "ok",Code: 200},true,true)
	if method=="GET"{
		params := GetParams(ctx.Request.RequestURI, method)
		log.Println("请求参数是 : ",params)
	}else {
		log.Println("请求参数是 : ", ctx.Request.Form)
	}
}

func GetParams(url,method string,) map[string]string{
	m := map[string]string{}
	if method=="POST" || url=="/"{
		return m
	}
	s := strings.Split(url, "?")[1]
	if s=="" {
		return m
	}
	split := strings.Split(s, "&")
	if split==nil || len(split)<=0 {
		return m
	}
	for _, item := range split {
		i := strings.Split(item, "=")
		m[i[0]] = i[1]
	}
	return m
}


